// 输入: [1,7,4,9,2,5]
// 输出: 6 
// 解释: 整个序列均为摆动序列。

function wingMaxlength(arr) {
    if (arr.length < 2) {
        return arr.length
    }
    let prediff = arr[0] - arr[1];
    let count = prediff === 0 ? 1 : 2
    for (let i = 0; i < arr.length; i++) {
        let diff = arr[0] - arr[1];
        if ((prediff <= 0 && diff > 0) || diff < 0 && prediff >= 0) {
            count++;
            prediff = diff
        }
    }
    return count
}